package com.qianfeng.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * api文档生成类
 * 注意：如果我们application.yml中配置context-path: /qfdata，则访问地址也需要加根目录。如本次访问为：
 * http://localhost:8080/qfdata/swagger-ui.html
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.qianfeng")) //扫描api的根目录
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("JavaWeb-Data-API")
                .description("第一个JavaWeb数据服务项目")
                //项目服务条款
                .termsOfServiceUrl("http://www.baidu.com/")
                .version("1.0")
                //最新的写法如下
                //公司的名字   公司的网址   邮箱
                .contact(new Contact("qianfeng","http://www.goodprogrammer.org/","775600040@qq.com"))
                .build();
    }
}

